import {Toast,Loading} from "../../utils/util";
Page({
  data: {
    name: '',
    zhanghao: '',
    mima: ''
  },
  backLogin() {
    wx.navigateTo({
      url: '../denglu/denglu',
    })
  },
  formSubmit(e) {
    console.log(e)
    let formDate = e.detail.value;
      for(var i in formDate){
        if(formDate[i] == ''){
          const msg = i == 'zhanghao' ? '用户名': i == 'mima' ? '密码':'确认密码';
          Toast("error",msg+"不能为空");
          return;
        }
      }
      if(formDate["mima"] != formDate["remima"]){
          Toast("none","确认密码和密码不一致");
          return;
      }
      wx.cloud.database().collection('user').add({
        data: {
          name: formDate["zhanghao"],
          zhanghao: formDate["zhanghao"],
          mima: formDate["mima"]
        },
        success(res) {
          console.log("注册成功", res)
          wx.navigateTo({
            url: '../denglu/denglu',
          })
        },
        fail(res) {
          console.log("注册失败", res)
        },
      })
  },
})